import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.*;

public class ShareMenuItemListener implements ActionListener{

	private String text;
	private MultiDraw2 md;
	
	ShareMenuItemListener(MultiDraw2 md, String text){
		this.text = text;
		this.md = md;
	}

	public void actionPerformed(ActionEvent e) {
		if(text.equals("shareTool")){
			JFileChooser chooser = new JFileChooser();
			String[] ext = new String[1];ext[0] = "class";
			FNameSuffixFilter fnsf = new FNameSuffixFilter(".class",ext);
			chooser.addChoosableFileFilter(fnsf);
			chooser.showOpenDialog(md);
			File f = chooser.getSelectedFile();
			if(f.getName().endsWith(".class")){
				md.mdUser.rt.shareToolFile = f;
				md.mdUser.remoteOut.println("<<UPLOADFILE>>"+f.getName());
				System.out.println("<<UPLOADFILE>>"+f.getName());
			}
		}else if(text.equals("testTool")){
			md.mdUser.remoteOut.println("<<TESTTOOL>>");
		}else if(text.equals("startTool")){
			String toolString = JOptionPane.showInputDialog(null, 
					"What tool would you like to add to the tool bar?\n"+
					"You must upload the necessary .class files in order for all users to use the tool.\n"+
					"e.g. <toolName>Tool.class and <toolName>Object.class");
			md.mdUser.remoteOut.println("<<STARTTOOL>>"+toolString);
		}
	}
}
